<UserControl x:Class="Assembly.Metro.Controls.PageTemplates.Games.Components.MetaComponents.MetaChunk"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d"
             HorizontalAlignment="Stretch"
             x:Name="metaChunk"
             d:DesignWidth="500"
             MinWidth="500">
    
    <UserControl.Style>
        <Style TargetType="UserControl">
            <Setter Property="Width" Value="{Binding Width}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsExpanded}" Value="False">
                    <Setter Property="Width" Value="{Binding ElementName=metaChunk, Path=MinWidth}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ComponentDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    
    <Border HorizontalAlignment="Stretch" Grid.ZIndex="1" BorderBrush="#FF474747" Padding="10,10,10,10">
        <Border.Style>
            <Style TargetType="Border">
                <Setter Property="BorderThickness" Value="1,1,1,0" />
                <Setter Property="Margin" Value="0,10,0,0" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsExpanded}" Value="False">
                        <Setter Property="BorderThickness" Value="1" />
                        <Setter Property="Margin" Value="0,10,0,10" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding HasChildren}" Value="False">
                        <Setter Property="BorderThickness" Value="1" />
                        <Setter Property="Margin" Value="0,10,0,10" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Border.Style>
        <Grid>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="110" />
                </Grid.ColumnDefinitions>
            
                <Label Grid.Column="0" x:Name="lblChunkName" Content="{Binding Name}" HorizontalAlignment="Stretch" Height="24" VerticalAlignment="Top" Margin="0,0,5,0" Foreground="#FF999999" Background="#FF474747" Padding="5,3"/>
                <ComboBox Grid.Column="1" x:Name="cbChunkIndex" HorizontalAlignment="Stretch" Height="24" Margin="5,0,0,0" VerticalAlignment="Top" ItemsSource="{Binding Pages}" SelectedIndex="{Binding CurrentIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding HasChildren}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Run Text="{Binding Index}" /><Run Text=" - " /><Run Text="{Binding DataContext.Length, ElementName=cbChunkIndex}" />
                            </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </Grid>
            <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="0,30,0,0">
                <Expander x:Name="InformationExpander" Header="Information" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                    <Grid Background="#FF979797" Height="30">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="150" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center">
                                <Label Content="Count:" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center" Background="{x:Null}" Foreground="#FF414141" />
                                <TextBox x:Name="txtChunkCount" Text="{Binding Length, Mode=OneWay}" HorizontalAlignment="Left" Height="24" Margin="10,0,0,0" VerticalAlignment="Center" Width="85" Foreground="#FF999999" Padding="0,0,0,0"/>
            
                                <Label Content="Offset:" HorizontalAlignment="Left" Margin="20,0,0,0" VerticalAlignment="Center" Background="{x:Null}" Foreground="#FF414141" />
                                <TextBox x:Name="txtChunkOffset" Text="{Binding FirstEntryOffset, Mode=OneWay}" HorizontalAlignment="Left" Height="24" Margin="10,0,0,0" VerticalAlignment="Center" Width="85" Foreground="#FF999999" Padding="0,0,0,0"/>
                            </StackPanel>
                            
                            <StackPanel Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,0,10,0">
                                <Label Content="Size:" HorizontalAlignment="Left" Margin="20,0,0,0" VerticalAlignment="Center" Background="{x:Null}" Foreground="#FF414141" />
                                <TextBox x:Name="txtChunkSize" Text="{Binding EntrySize, Mode=OneWay}" HorizontalAlignment="Left" Height="24" Margin="10,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center" Width="85" Foreground="#FF999999" Padding="0,0,0,0"/>
                            </StackPanel>
                        </Grid>
                    </Grid>
                </Expander>
            
                <Expander Header="Contents" Margin="0,10,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top" IsEnabled="{Binding HasChildren}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}" />
            </StackPanel>
        </Grid>
    </Border>
</UserControl>
